package org.dlsu.mt.parser;

import java.util.Vector;

public class VectoredLexer implements LexerInterface{

	/** The list of tokens */
	Vector tokens;
	/** The marker for the current token*/
	int marker = 0;

	/**
	 * Creates a new VectoredLexer with the given vector
	 *
	 * @param tokens The list of tokens as a vector
	 */
	 public VectoredLexer(Vector tokens) {
		 marker = 0;
		 this.tokens = tokens;
	 }

	 private VectoredLexer() {
		 marker=0;
	 }

	/**
	 * Gets the next token from the lexical analyzer
	 *
	 * @return Returns the token as a Word object
	 */
	public Word nextToken(){
		return (Word) tokens.elementAt(marker++);
	}

	/**
	 * Gets the ith token from the lexical analyzer
	 *
	 * @param i The ith index of the lexical analyzer
	 * @return Returns the token as a Word object
	 */
	public Word getToken(int i){
		return (Word) tokens.elementAt(i);
	}

	/**
	 * Sets the position of the marker
	 *
	 * @return Returns the token as a Word object
	 */
	public void setMarker(int i){
		marker = i;
	}

	/**
	 * Determines if there are still more tokens inside the lexical analyzer
	 *
	 * @return Returns true if the lexical analyzer has not exhausted all the tokens, otherwise false
	 */
	public boolean hasMoreTokens(){
		if (marker < tokens.size())
			return true;
		else
			return false;
	}

	/**
	 * Creates a copy of the current object
	 *
	 * @return Returns a unique copy of the list of tokens and the position of the marker
	 */
	public Object clone()
	{
		VectoredLexer lex = new VectoredLexer();

		lex.setMarker(this.marker);
		lex.tokens = (Vector)(this.tokens).clone();

		return lex;
	}
}